package com.cnswhy.cloud.server.common.entity.enumeration;

import com.cnswhy.cloud.common.core.base.BaseEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.stream.Stream;

/**
 * <p>
 * 银行卡类型
 * </p>
 *
 * @author cnswhy
 * @date 2020-10-24
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "BankCardType", description = "银行卡类型-枚举")
public enum BankCardType implements BaseEnum {

    /**
     * DEBIT_CARD 借记卡
     */
    DEBIT_CARD(0,"借记卡"),
    /**
     * CREDIT_CARD 贷记卡
     */
    CREDIT_CARD(1,"贷记卡"),

    /**
     * SEMI_CREDIT_CARD 准贷记卡
     */
    SEMI_CREDIT_CARD(2,"准贷记卡"),
    /**
     * DEBIT_CREDIT_CARD 借贷合一卡
     */
    DEBIT_CREDIT_CARD(3,"借贷合一卡"),
    /**
     * PREPAID_CARD 预付费卡
     */
    PREPAID_CARD(4,"预付费卡"),
    /**
     * UNKNOWN 未知
     */
    UNKNOWN(5,"未知"),
    ;

    @ApiModelProperty(value = "描述")
    private int val;

    private String desc;


    /**
     * 跟就当前枚举的name匹配
     */
    public static BankCardType match(String val, BankCardType def) {
        return Stream.of(values()).parallel().filter((item) -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static BankCardType get(String val) {
        return match(val, null);
    }

    public boolean eq(BankCardType val) {
        return val == null ? false : eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "编码", allowableValues = "DEBIT_CARD,CREDIT_CARD,SEMI_CREDIT_CARD,DEBIT_CREDIT_CARD,PREPAID_CARD", example = "DEBIT_CARD")
    public String getCode() {
        return this.name();
    }

}
